#include "ChallengeResultDialog.h"
#include "../../../model/proxy/ChanllengeProxy.h"
#include "../../../model/proxy/UserProxy.h"
#include "../../../utils/LocalString.h"

ChallengeResultDialog::ChallengeResultDialog(void)
	:mName1(NULL),mName2(NULL),mGetGold(NULL),mGetExp(NULL),mTitle(NULL)
{
}

ChallengeResultDialog::~ChallengeResultDialog(void)
{
	CC_SAFE_RELEASE(mName1);
	CC_SAFE_RELEASE(mName2);
	CC_SAFE_RELEASE(mGetGold);
	CC_SAFE_RELEASE(mGetExp);
	CC_SAFE_RELEASE(mTitle);
}

bool ChallengeResultDialog::init()
{
	return true;
}

SEL_MenuHandler ChallengeResultDialog::onResolveCCBCCMenuItemSelector(CCObject * pTarget, CCString * pSelectorName )
{
	CCB_SELECTORRESOLVER_CCMENUITEM_GLUE(this, "onDoItClick", ChallengeResultDialog::onDoItClick);
	return NULL;
}

SEL_CCControlHandler ChallengeResultDialog::onResolveCCBCCControlSelector( CCObject * pTarget, CCString * pSelectorName )
{
	CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onPlayerInfoBtnClick", ChallengeResultDialog::onPlayerInfoBtnClick);
	CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onReturnBtnClick", ChallengeResultDialog::onReturnBtnClick);
	return NULL;
}

bool ChallengeResultDialog::onAssignCCBMemberVariable( CCObject * pTarget, CCString * pMemberVariableName, CCNode * pNode )
{
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mName1", CCLabelTTF *, this->mName1);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mName2", CCLabelTTF *, this->mName2);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mGetGold", CCLabelTTF *, this->mGetGold);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mGetExp", CCLabelTTF *, this->mGetExp);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mTitle", CCLabelTTF *, this->mTitle);
	return false;
}

void ChallengeResultDialog::onNodeLoaded( CCNode * pNode, CCNodeLoader * pNodeLoader )
{

}

void ChallengeResultDialog::onEnter()
{
	ModelDialog::onEnter();
}

void ChallengeResultDialog::onExit()
{
	ModelDialog::onExit();
}

void ChallengeResultDialog::refresh()
{
	ChallengeResult& mChallengeResult = ChanllengeProxy::getSingletonPtr()->mChallengeResult;
	ChallengeEnemyInfo* challengeEnemyInfo = ChanllengeProxy::getSingletonPtr()->curChallengeEnemyInfo;
	mName1->setString(UserProxy::getSingletonPtr()->userVO.name.c_str());
	mName2->setString(challengeEnemyInfo->name.c_str());
	if(mChallengeResult.result == 1)
	{
		mTitle->setString(gls("battle_succeed"));
		mGetGold->setString(fcs("+%d", challengeEnemyInfo->succeedGold));
		mGetExp->setString(fcs("+%d", challengeEnemyInfo->succeedExp));
	}
	else
	{
		mTitle->setString(gls("battle_failed"));
		mGetGold->setString(fcs("-%d", challengeEnemyInfo->failedGold));
		mGetExp->setString(fcs("%d", 0));
	}
	
}

void ChallengeResultDialog::_onNotification( CCObject* object )
{
	
}

void ChallengeResultDialog::onDoItClick(CCObject* pSender)
{
    
}

void ChallengeResultDialog::onPlayerInfoBtnClick( CCObject * pSender, CCControlEvent pCCControlEvent )
{
    close();
}

void ChallengeResultDialog::onReturnBtnClick( CCObject * pSender, CCControlEvent pCCControlEvent )
{
	close();
}
